using System;
using System.Text;

namespace FeedFly
{
    /// <summary>
    /// Enum for different Notification types
    /// </summary>
    public enum NotificationMessageType
    {
        Message,
        Error
    }

    /// <summary>
    /// Structure for sending notifications to delegate for updating UI 
    /// It's added to a generics queue on the main navigation screen to
    ///   only allow one notification to be visible at a time.
    /// </summary>
    public struct NotificationMessage
    {
        public string Caption;
        public string Message;
        public string UnformattedMessage;
        NotificationMessageType MessageType;
        private const string APP_TITLE = " | FeedFly";
        
        public NotificationMessage(NotificationMessageType messageType, string message)
        {
            Caption = NotificationMessage.BuildCaption(messageType);
            Message = BuildMessage(messageType, message);
            MessageType = messageType;
            UnformattedMessage = message;
        }

        public NotificationMessage(string message)
        {
            MessageType = NotificationMessageType.Message;
            Caption = NotificationMessage.BuildCaption(MessageType);
            Message = BuildMessage(MessageType, message);            
            UnformattedMessage = message;
        }

        private static string BuildCaption(NotificationMessageType messageType)
        {
            StringBuilder caption = new StringBuilder(100);
            caption.Append(System.DateTime.Now.ToShortTimeString()).Append(APP_TITLE);
            return caption.ToString();
        }

        private static string BuildMessage(NotificationMessageType messageType, string message)
        {
            StringBuilder html = new StringBuilder(300 + message.Length);

            html.Append("<html><body><form method=\"GET\" action=response><p><table align=\"right\" style=\"padding-left:3px\"><tr><td><input type='submit' value='Dismiss' /><br /><a href=\"details\">Log&nbsp;to&nbsp;File</a></td></tr></table>");

            if (messageType == NotificationMessageType.Error)
                html.Append("<span style=\"color:red;font-weight:bold\">Error:</span><br />");

            html.Append(message);
            html.Append("</p></body></html>");

            return html.ToString();
        }
    }
}
